/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 12.09.12
 * Time: 10:14
 * To change this template use File | Settings | File Templates.
 */
package fgui{
import flash.geom.Point;

import mx.controls.Image;
import mx.core.UIComponent;

/**
 * Main class for rendering components.
 *
 * @see com.fgui.GuiComponent
 */
public class GuiComponent extends UIGraphicsComponent {
    public var cId:int;
    public var cName:String;

    protected var bgWidth:int;
    protected var bgHeight:int;
    protected var bgImage:Image;
    protected var margin:int = 10;

    private var _renderColor:uint;
    private var _renderAlpha:Number;

    /**
     *
     * @param coordinate - coordinate/position of this component
     * @param size - width (x) and height (y)
     */
    public function GuiComponent(coordinate:Point, size:Point) {
        super();
        this.x = coordinate.x;
        this.y = coordinate.y;
        this.bgWidth = size.x;
        this.bgHeight = size.y;
        this.renderDefault();
    }

    /**
     * @description Use this function when need render component
     */
    public function renderDefault():void {
        this.graphics.clear();
        this.graphics.beginFill(_renderColor, _renderAlpha);
        this.graphics.drawRoundRect(0, 0, this.bgWidth, this.bgHeight, 20, 20);
        this.graphics.endFill();
    }

    /**
     *
     * @param color - backgroung color
     * @param alpha - backgroung alpha
     *
     * @description Use this unction if you need render component with custom parameters
     */
    public function renderCustom(color:uint = 0xeeeeee, alpha:Number = 1):void {
        this.graphics.clear();
        this.graphics.beginFill(color, alpha);
        this.graphics.drawRoundRect(0, 0, this.bgWidth, this.bgHeight, 15, 15);
        this.graphics.endFill();
    }

    public function getCoordinate():Point {
        return new Point(this.x, this.y);
    }

    public function setCoordinate(point:Point):void {
        this.x = point.x;
        this.y = point.y;
    }

    public function getSize():Point {
        return new Point(this.bgWidth, this.bgHeight);
    }

    public function setSize(point:Point):void {
        this.bgWidth = point.x;
        this.bgHeight = point.y;
        this.renderDefault();
    }

    public function get renderColor():uint {
        return _renderColor;
    }

    public function set renderColor(value:uint):void {
        _renderColor = value;
    }

    public function get renderAlpha():Number {
        return _renderAlpha;
    }

    public function set renderAlpha(value:Number):void {
        _renderAlpha = value;
    }
}
}
